#pragma once
#include "DirtyProperty.hpp"
#include "Box.hpp"
#include "Vertex.hpp"
#include <vector>
#include "TextureAtlas.hpp"
#include "Matrix4x4.hpp"

namespace Typhoon {
	class Mesh
	{
	public:
		Mesh();
		~Mesh();

		typedef std::vector<Vertex> VerticesList;
		typedef std::vector<short> TrianglesList;
		
		VerticesList& Vertices();
		TrianglesList& Triangles();

		virtual const VerticesList& ReadOnlyVertices();
		virtual const TrianglesList& ReadOnlyTriangles();

		DirtyProperty<Mesh*, Box> BoundingBox;

		void AddQuad(Vector2 center, Vector2 size, Colour color);
        void AddTriangle(Vector2 p1, Vector2 p2, Vector2 p3, Colour color);
		void AddTexturedQuad(Texture* texture, const Box& textureCoords, const Matrix3x3& transform);
		void AddTexturedQuad(TextureAtlas* atlas, const std::string& name);
		void AddTexturedQuad(TextureAtlas* atlas, const std::string& name, float scale);
		void AddTexturedQuad(TextureAtlas* atlas, const std::string& name, float scale, Vector2 center, float rotation);

		void SetColor(const Colour& color);
		void SetAlpha(const float& alpha);
        
        void Clear();

		void AddCube(Vector3 center, Vector3 size, Colour color);

		void AddTriangle(const Vector3& p1, const Vector3& p2, const Vector3& p3,
			const Vector3& n1, const Vector3& n2, const Vector3& n3,
			const Vector2& texCoord1, const Vector2& texCoord2, const Vector2& texCoord3, 
			const Colour& color, const Matrix4x4& world);

	protected:
		VerticesList vertices;
		TrianglesList triangles;

	private:
		void CalcBoundingBox(DirtyProperty<Mesh*, Box>::EventData& eventData);

		


	};
}